home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / diskutil / backup.arc / BKUPSEL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-01-04  |  10.5 KB  |  374 lines

  1. /* public domain; all rights reserved by: Robert F. Ritter (c) 1986 */
  2.  
  3. #include "osbind.h"
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11. #define ARC "\\bin\\arc"  /* where is your arc situated? */
  12.  
  13.  
  14.  
  15.  
  16.  
  17. struct dta {
  18.  
  19.                 char  reserved[21];
  20.  
  21.                 char  fab;
  22.  
  23.                 unsigned time;
  24.  
  25.                 unsigned date;
  26.  
  27.                 long  size;
  28.  
  29.                 char  name[];
  30.  
  31.            };
  32.  
  33.  
  34.  
  35. struct dta *dta_ptr;
  36.  
  37.  
  38.  
  39. unsigned sys_time, sys_date;
  40.  
  41.  
  42.  
  43. int     contrl[ 12 ],
  44.  
  45.         intin[ 256 ], ptsin[ 256 ],
  46.  
  47.         intout[ 256 ], ptsout[ 256 ],
  48.  
  49.         workin[]={ 1,1,1,1,1,1,1,1,1,1,2 }, workout[ 57 ],
  50.  
  51.         handle,
  52.  
  53.         i, j,
  54.  
  55.         x, y, w, h,
  56.  
  57.         xdial, ydial, wdial, hdial,
  58.  
  59.         k = 0,
  60.  
  61.         file_handle, myfile, oldfile,
  62.  
  63.         button,
  64.  
  65.         ret;
  66.  
  67.  
  68.  
  69. long    space,
  70.  
  71.         box_adr;
  72.  
  73.  
  74.  
  75. char    path[50],
  76.  
  77.         volume[50],
  78.  
  79.         name[50],
  80.  
  81.         drive[3],
  82.  
  83.         crlf[2],
  84.  
  85.         today[10],
  86.  
  87.         totime[10],
  88.  
  89.         realdta[44],
  90.  
  91.         out_filename[12],
  92.  
  93.         disk_no[4];
  94.  
  95.  
  96.  
  97. long strlen(string)
  98.  
  99.   char *string;
  100.  
  101.   {
  102.  
  103.         char *string_pointer = string;
  104.  
  105.  
  106.  
  107.         while ( *string_pointer )
  108.  
  109.            ++string_pointer;
  110.  
  111.  
  112.  
  113.         return ((long) string_pointer - string );
  114.  
  115.  
  116.  
  117.   }
  118.  
  119.  
  120.  
  121. char * strcat(s, t)
  122.  
  123.   char s[], t[];
  124.  
  125. {
  126.  
  127.         int i, j;
  128.  
  129.         i = j = 0;
  130.  
  131.         while(s[i] != '\0')          /* find end of s */
  132.  
  133.            i++;
  134.  
  135.         while((s[i++] = t[j++]) != '\0');   /* copy t */
  136.  
  137. }
  138.  
  139.  
  140.  
  141. char strcpy(s, t)
  142.  
  143.   char *s, *t;
  144.  
  145. {
  146.  
  147.         while(*s++ = *t++);
  148.  
  149. }
  150.  
  151.  
  152.  
  153. strequ ( str1, str2 )
  154.  
  155.   char str1[], str2[];
  156.  
  157.     {
  158.  
  159.         int i = 0, answer;
  160.  
  161.         while( str1[i] == str2[i] && str1[i] != '\0'
  162.  
  163.                                   && str2[i] != '\0' )
  164.  
  165.           ++i;
  166.  
  167.         if( str1[i] == '\0' && str2[i] == '\0' )
  168.  
  169.           answer = 1;
  170.  
  171.         else
  172.  
  173.           answer = 0;
  174.  
  175.         return( answer );
  176.  
  177.     }
  178.  
  179.  
  180.  
  181. itoa (n, s)
  182.  
  183.   char s[];
  184.  
  185.   int n;
  186.  
  187.     {
  188.  
  189.         int i;
  190.  
  191.         i = 2;
  192.  
  193.         strcpy(s, "000");
  194.  
  195.         do {
  196.  
  197.             s[i--] = (n % 10) + '0';
  198.  
  199.             } while ((n /= 10) > 0);
  200.  
  201.     }
  202.  
  203.  
  204.  
  205. ltoa (n, s)
  206.  
  207.   char s[10];
  208.  
  209.   long n;
  210.  
  211.     {
  212.  
  213.         long n2;
  214.  
  215.         int i;
  216.  
  217.         n2 = n;
  218.  
  219.         i = 9;
  220.  
  221.         do {
  222.  
  223.             s[i--] = n2 - ((n2 / 10) * 10) + '0';
  224.  
  225.             } while ((n2 /= 10) > 0);
  226.  
  227.     }
  228.  
  229.  
  230.  
  231. itodate (idate, date)
  232.  
  233.   unsigned idate;
  234.  
  235.   char date[10];
  236.  
  237.   {
  238.  
  239.         unsigned yy, mm, dd;
  240.  
  241.  
  242.  
  243.         yy = (idate >> 9 & 0x7F) + 80;
  244.  
  245.         mm = idate >> 5 & 0xF;
  246.  
  247.         dd = idate & 0x1F;
  248.  
  249.  
  250.  
  251.         date[0] = (dd/10) + '\060';
  252.  
  253.         date[1] = (dd%10) + '\060';
  254.  
  255.         date[2] = '/';
  256.  
  257.         date[3] = (mm/10) + '\060';
  258.  
  259.         date[4] = (mm%10) + '\060';
  260.  
  261.         date[5] = '/';
  262.  
  263.         date[6] = (yy/10) + '\060';
  264.  
  265.         date[7] = (yy%10) + '\060';
  266.  
  267.   }
  268.  
  269.  
  270.  
  271. itotime (itime, time)
  272.  
  273.    unsigned itime;
  274.  
  275.    char time[10];
  276.  
  277.   {
  278.  
  279.         unsigned hrs, mins, secs;
  280.  
  281.  
  282.  
  283.         hrs = itime >> 11 & 0x1F;
  284.  
  285.         mins = itime >> 5 & 0x3F;
  286.  
  287.         secs = (itime & 0x1F) << 1;
  288.  
  289.  
  290.  
  291.         time[0] = (hrs/10) + '\060';
  292.  
  293.         time[1] = (hrs%10) + '\060';
  294.  
  295.         time[2] = ':';
  296.  
  297.         time[3] = (mins/10) + '\060';
  298.  
  299.         time[4] = (mins%10) + '\060';
  300.  
  301.         time[5] = ':';
  302.  
  303.         time[6] = (secs/10) + '\060';
  304.  
  305.         time[7] = (secs%10) + '\060';
  306.  
  307.   }
  308.  
  309.  
  310.  
  311. int stoi(string)
  312.  
  313. char string[];
  314.  
  315. {
  316.  
  317.         int i, int_val, result=0;
  318.  
  319.         for (i=0; string[i] >= '0' && string[i] <= '9'; ++i){
  320.  
  321.                 int_val = string[i] - '0';
  322.  
  323.                 result = result * 10 + int_val;
  324.  
  325.         }
  326.  
  327.         return(result);
  328.  
  329. }
  330.  
  331.  
  332.  
  333.  
  334.  
  335. /*************************************************/
  336.  
  337. main(argc, argv)
  338.  
  339. char **argv;
  340.  
  341. int    argc;
  342.  
  343.    {
  344.  
  345.         int x;
  346.  
  347.         int i, j, k;
  348.  
  349.         char  cc[20], xx[20];
  350.  
  351.         unsigned hrs=0, mins=0, secs=0, yy=80, mm=0, dd=0;
  352.  
  353.         int counter;
  354.  
  355.  
  356.  
  357.     crlf[0] = 0x0d;
  358.  
  359.     crlf[1] = 0x0a;
  360.  
  361.  
  362.  
  363.     oldfile = Fopen( "bkuptime", 0);
  364.  
  365.     myfile = Fcreate("newtime", 0);
  366.  
  367.  
  368.  
  369.     if (argc < 2) {
  370.  
  371.         Fwrite(0, 41L, "usage: BKUPSEL path <dd/mm/yy> <hh:mm:ss>");
  372.  
  373.         Fwrite(0, 2L, crlf);
  374.  
  375.         exit(-1);
  376.  
  377.         }
  378.  
  379.     else {
  380.  
  381.     strcpy(cc, "00/00/80");
  382.  
  383.         if (argc >= 3)
  384.  
  385.            strcpy(cc, argv[2]); /* the date to select by */
  386.  
  387.         else Fread(oldfile, 10L, cc);
  388.  
  389.  
  390.  
  391.         Fwrite(0, 38L, "Preparing backup list of files since: ");
  392.  
  393.         Fwrite(0, 8L, cc);
  394.  
  395.         Fwrite(0, 2L, "  ");
  396.  
  397.  
  398.  
  399.         i = strlen(cc);
  400.  
  401.  
  402.  
  403.         counter = 0;
  404.  
  405.         k = 0;
  406.  
  407.         for (j=0; j<=i;++j){
  408.  
  409.                 if (cc[j] >= '0' && cc[j] <= '9'){
  410.  
  411.                         xx[k] = cc[j];
  412.  
  413.                         ++k;
  414.  
  415.                         }
  416.  
  417.                 else {
  418.  
  419.                         xx[k] = '\0';
  420.  
  421.                         x = stoi(xx);
  422.  
  423.                         k = 0;
  424.  
  425.                         ++counter;
  426.  
  427.                         switch(counter){
  428.  
  429.                            case 1:
  430.  
  431.                                 if (x <= 31 && x > 0) dd = x;
  432.  
  433.                                 break;
  434.  
  435.                            case 2:
  436.  
  437.                                 if (x <= 12 && x > 0) mm = x;
  438.  
  439.                                 break;
  440.  
  441.                            case 3:
  442.  
  443.                                 if (x >= 80) yy = x;
  444.  
  445.                                 break;
  446.  
  447.                            } /* switch */
  448.  
  449.                         } /* else */
  450.  
  451.                 } /* for */
  452.  
  453.  
  454.  
  455.     strcpy(cc, "00:00:00");
  456.  
  457.         if (argc >= 4)
  458.  
  459.            strcpy(cc, argv[3]); /* the time to select by */
  460.  
  461.         else Fread(oldfile, 8L, cc);
  462.  
  463.  
  464.  
  465.         Fwrite(0, 8L, cc);
  466.  
  467.  
  468.  
  469.         i = strlen(cc);
  470.  
  471.  
  472.  
  473.         counter = 0;
  474.  
  475.         k = 0;
  476.  
  477.         for (j=0; j<=i; j++){
  478.  
  479.                 if (cc[j] >= '0' && cc[j] <= '9'){
  480.  
  481.                         xx[k] = cc[j];
  482.  
  483.                         ++k;
  484.  
  485.                         }
  486.  
  487.                 else {
  488.  
  489.                         xx[k] = '\0';
  490.  
  491.                         x = stoi(xx);
  492.  
  493.                         k = 0;
  494.  
  495.                         ++counter;
  496.  
  497.                         switch(counter){
  498.  
  499.                            case 1:
  500.  
  501.                                 if (i!= 0 && x <= 23 && x >= 0) hrs=x;
  502.  
  503.                                 break;
  504.  
  505.                            case 2:
  506.  
  507.                                 if (x <= 59 && x >= 0) mins = x;
  508.  
  509.                                 break;
  510.  
  511.                            case 3:
  512.  
  513.                                 if (x <= 59 && x >= 0) secs = x;
  514.  
  515.                                 break;
  516.  
  517.                            }
  518.  
  519.                         }
  520.  
  521.                 }
  522.  
  523.         sys_time = (hrs << 11) + (mins << 5) + (secs >> 1);
  524.  
  525.         sys_date = ((yy - 80) << 9) + (mm << 5) + dd;
  526.  
  527.  
  528.  
  529.         strcpy(out_filename, "thisbkup.sh");
  530.  
  531.         file_handle = Fcreate(out_filename, 0);
  532.  
  533.  
  534.  
  535.         dta_ptr = (struct dta *) realdta;
  536.  
  537.         Fsetdta(dta_ptr);
  538.  
  539.  
  540.  
  541.         Fwrite(0, 2L, crlf);
  542.  
  543.  
  544.  
  545.         strcpy( drive, argv[1]);
  546.  
  547.         read_the_directory();
  548.  
  549.  
  550.  
  551.         sys_time = Tgettime();
  552.  
  553.         sys_date = Tgetdate();
  554.  
  555.         itotime(sys_time, totime);
  556.  
  557.         itodate(sys_date, today);
  558.  
  559.         Fwrite(myfile, 8L, today);
  560.  
  561.         Fwrite(myfile, 2L, crlf);
  562.  
  563.         Fwrite(myfile, 8L, totime);
  564.  
  565.         Fwrite(myfile, 2L, crlf);
  566.  
  567.         }
  568.  
  569.    }
  570.  
  571. /*************************************************/
  572.  
  573.  
  574.  
  575.  
  576.  
  577. /*************************************************/
  578.  
  579. read_the_directory()
  580.  
  581.    {
  582.  
  583.      char thispath[50], cur_dir[50], charspace[10], totals[50];
  584.  
  585.         strcpy(path, drive);
  586.  
  587.         strcpy( thispath, path );
  588.  
  589.         strcat( thispath, "\\*.*" );
  590.  
  591.         ret = Fsfirst(thispath,0x10); /* get the first item on the volume   */
  592.  
  593.         while (ret == 0)
  594.  
  595.           {
  596.  
  597.             if (dta_ptr->fab == 0x10)               /* found a directory     */
  598.  
  599.                {if (   (!strequ( dta_ptr->name, "." ))
  600.  
  601.                     && (!strequ( dta_ptr->name, ".." )) )
  602.  
  603.                  {
  604.  
  605.                    strcpy(cur_dir,dta_ptr->name);
  606.  
  607.                    dir_write(path,cur_dir);        /* follow the directory */
  608.  
  609.                    ret = Fsfirst(thispath,0x10);
  610.  
  611.                      /*return to start of previous path */
  612.  
  613.                    while ((ret == 0) && (!strequ(dta_ptr->name, cur_dir)))
  614.  
  615.                       ret = Fsnext();
  616.  
  617.                  }
  618.  
  619.                }
  620.  
  621.               else dta_write(drive);                /* write the filename    */
  622.  
  623.  
  624.  
  625.             ret = Fsnext();           /* now walk the rest of the structure  */
  626.  
  627.            }
  628.  
  629.    }
  630.  
  631. /*************************************************/
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639. /*************************************************/
  640.  
  641. dta_write(path)
  642.  
  643.  char *path;
  644.  
  645.   {
  646.  
  647.     char command[100];
  648.  
  649.     
  650.  
  651.     if ((dta_ptr->date > sys_date) || 
  652.  
  653.     (dta_ptr->date == sys_date && dta_ptr->time >= sys_time)) {
  654.  
  655.         strcpy(name, path);
  656.  
  657.         strcat(name, "\\");
  658.  
  659.         strcat(name, dta_ptr->name);
  660.  
  661.  
  662.  
  663.     strcpy(command, ARC);
  664.  
  665.  
  666.  
  667.     strcat(command, " u $1 ");
  668.  
  669.         Fwrite(file_handle, (long) strlen(command), command);
  670.  
  671.         Fwrite(file_handle, strlen(name), name);
  672.  
  673.         Fwrite(file_handle, 2L, crlf);
  674.  
  675.         }
  676.  
  677.    }
  678.  
  679. /*************************************************/
  680.  
  681.  
  682.  
  683.  
  684.  
  685. /*************************************************/
  686.  
  687. dir_write(cur_path,directory)
  688.  
  689.   char *cur_path, *directory;
  690.  
  691.     {
  692.  
  693.     auto char new_path[50], thispath[50], cur_dir[50];
  694.  
  695.         strcpy( new_path, cur_path );
  696.  
  697.         strcat( new_path, "\\" );
  698.  
  699.         strcat( new_path, directory );
  700.  
  701.         strcpy( thispath, new_path);
  702.  
  703.         strcat( thispath, "\\*.*");
  704.  
  705.         ret = Fsfirst(thispath,0x10);  /* get this new path started */
  706.  
  707.         while (ret == 0)
  708.  
  709.           {
  710.  
  711.             if (dta_ptr->fab == 0x10)              /* found a directory     */
  712.  
  713.                {if (   (!strequ( dta_ptr->name, "." ))
  714.  
  715.                     && (!strequ( dta_ptr->name, ".." )) )
  716.  
  717.                  {
  718.  
  719.                    strcpy(cur_dir,dta_ptr->name);
  720.  
  721.                    dir_write(new_path,cur_dir);     /* follow the directory */
  722.  
  723.                    ret = Fsfirst(thispath,0x10);
  724.  
  725.                      /*return to start of previous path */
  726.  
  727.                    while ((ret == 0) && (!strequ(dta_ptr->name, cur_dir)))
  728.  
  729.                       ret = Fsnext();
  730.  
  731.                  }
  732.  
  733.                }
  734.  
  735.             else dta_write(new_path);              /* write the filename    */
  736.  
  737.  
  738.  
  739.             ret = Fsnext();           /* now walk the rest of the structure  */
  740.  
  741.            }
  742.  
  743.     }
  744.  
  745. /*************************************************/
  746.  
  747.